package com.dzsw.javabase.regx;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class OrderBySample {

    public static void main(String[] args) {
        String regx = "(?i)ORDER\\s+BY\\s+([\\w\\.,\\s]+)";

        String s = "SELECT * FROM ( SELECT TMP.*, ROWNUM ROW_ID FROM ( SELECT * FROM ATTENTION order \r\n\t BY CODE,     BASE ) TMP WHERE ROWNUM <= ? ) WHERE ROW_ID > ?";
        String ss = "SELECT *\n" +
                "          FROM ATTENTION\n" +
                "         ORDER BY CODE";
        String sss = "SELECT * \n" + "FROM ATTENTION\n" + "        ORDER BY CODE";
        Pattern p = Pattern.compile(regx);
        Matcher m = p.matcher(s);
        System.out.println("s >> " + m.find() + ", g >> " + m.group());
        m = p.matcher(ss);
        System.out.println("ss >> " + m.find() + ", g >> " + m.group());
        m = p.matcher(sss);
        System.out.println("sss >> " + m.find() + ", g >> " + m.group());

    }
}
